package cn.com.oceansoft.business.danger.controller;

import cn.com.oceansoft.business.base.controller.BaseController;
import cn.com.oceansoft.business.base.entity.Pager;
import cn.com.oceansoft.business.base.entity.Query;
import cn.com.oceansoft.business.base.entity.Result;
import cn.com.oceansoft.business.danger.entity.*;
import cn.com.oceansoft.business.danger.service.ICollecterInfoService;
import cn.com.oceansoft.business.danger.service.IDangerContentService;
import cn.com.oceansoft.business.danger.service.IWzzjService;
import cn.com.oceansoft.nos.common.util.MD5Util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;

/**
 * Created by lenovo on 2018/5/3.
 */
@Controller
@RequestMapping("danger")
public class DangerDeatilController extends BaseController {
    @Resource
    private ICollecterInfoService collecterInfoService;
    @Resource
    private IDangerContentService dangerContentService;
    @Resource
    private IWzzjService wzzjService;

    @RequestMapping("info/list")
    public String list(Model model, Query query, CollecterInfo collecterInfo, HttpServletRequest request) {
        int mark = 0;
        if ("".equals(collecterInfo.getYhlb()) || null == collecterInfo.getYhlb()) {
            collecterInfo.setYhlb(null);
        }
        if ("".equals(collecterInfo.getFjid()) || null == collecterInfo.getFjid()) {
            collecterInfo.setFjid(getMemberSession().getFjid());
            // collecterInfo=getMemberSession();
            mark = 1;
            if (getMemberSession().getRoletype().equals("1")) {
                collecterInfo.setPcsid(getMemberSession().getPcsid());
                collecterInfo.setSqid("");
            } else if (getMemberSession().getRoletype().equals("2")) {
                collecterInfo.setPcsid(getMemberSession().getPcsid());
                collecterInfo.setSqid(getMemberSession().getSqid());
            } else {
                collecterInfo.setPcsid("");
                collecterInfo.setSqid("");
            }

        }
        query.setData(collecterInfo);
        model.addAttribute("query", query);
        model.addAttribute("pager", dangerContentService.getNrList(query));
        if ("".equals(collecterInfo.getFjid()) || null == collecterInfo.getFjid()) {
            model.addAttribute("dicone", collecterInfoService.getdict(collecterInfo));
        } else {
            CollecterInfo one = new CollecterInfo();
            one.setFjid(collecterInfo.getFjid());
            if ("".equals(getMemberSession().getFjid()) || null == getMemberSession().getFjid()) {
                CollecterInfo collecterInfo1 = new CollecterInfo();
                collecterInfo1.setFjid("");
                model.addAttribute("dicone", collecterInfoService.getdict(collecterInfo1));
            } else {
                model.addAttribute("dicone", collecterInfoService.getonedict(one));
            }
            if (getMemberSession().getRoletype().equals("1") || getMemberSession().getRoletype().equals("2")) {
                CollecterInfo collecterInfo1 = new CollecterInfo();
                collecterInfo1.setFjid(getMemberSession().getPcsid());
                model.addAttribute("dictwo", collecterInfoService.getonedict(collecterInfo1));
            } else {
                model.addAttribute("dictwo", collecterInfoService.getdict(one));
            }
            if (getMemberSession().getRoletype().equals("1")) {
                collecterInfo.setPcsid(getMemberSession().getPcsid());
                if (!"".equals(collecterInfo.getPcsid()) && null != collecterInfo.getPcsid()) {
                    one.setPcsid(collecterInfo.getPcsid());
                    model.addAttribute("dicthree", collecterInfoService.getdict(collecterInfo));
                }
            } else if (getMemberSession().getRoletype().equals("2")) {
                CollecterInfo collecterInfo1 = new CollecterInfo();
                collecterInfo1.setFjid(getMemberSession().getSqid());
                model.addAttribute("dicthree", collecterInfoService.getonedict(collecterInfo1));
            } else {
                if (!"".equals(collecterInfo.getPcsid()) && null != collecterInfo.getPcsid()) {
                    one.setPcsid(collecterInfo.getPcsid());
                    model.addAttribute("dicthree", collecterInfoService.getdict(collecterInfo));
                }
            }


        }
        if (!"".equals(collecterInfo.getChildtype()) && null != collecterInfo.getChildtype()) {
            DangerContent dc = new DangerContent();
            dc.setType(collecterInfo.getYhlb());
            model.addAttribute("dicfour", collecterInfoService.getChildtype(dc));
        }
        return "danger/info_list";
    }

    @RequestMapping("info/detail")
    public String detail(Model model, DangerContent dangerContent, HttpServletRequest request) {
        DangerContent data = dangerContentService.getInfoDetail(dangerContent);
        model.addAttribute("data", data);
        model.addAttribute("pic", dangerContentService.getInfoPic(dangerContent));
        String[] arr = data.getChildtype().split(",");
        String name = "";
        for (int i = 0; i < arr.length; i++) {
            if (!"".equals(arr[i]) && null != arr[i]) {
                name += "'" + arr[i] + "'";
                if (i < arr.length - 1) {
                    name += ",";
                }
            }

        }
        dangerContent.setChildtype(name);
        List<CollecterInfo> list = dangerContentService.getDictList(dangerContent);
        model.addAttribute("child", list);
        Flowinfo flowinfo = new Flowinfo();
        flowinfo.setDangerid(dangerContent.getId());
        flowinfo.setOpertype("2");
        model.addAttribute("lz", dangerContentService.getInfoDetailLz(flowinfo));
        //model.addAttribute("fkpic",dangerContentService.getInfoPicfk(dangerContent));


        List<Flowinfo> listFlowInfo = dangerContentService.getListFlowInfo(flowinfo);//获取所有流程
        for (Flowinfo fInfo : listFlowInfo) {
            String type = fInfo.getOpertype();
            if ("6".equals(type)) {
                fInfo.setCfcs(dangerContentService.getCfcs(fInfo.getId()));
                fInfo.setZgcs(dangerContentService.getZgcs(fInfo.getId()));
                fInfo.setAttach(dangerContentService.getPicFK(fInfo.getId()));
            }
        }
        model.addAttribute("flowInfo", listFlowInfo);

//        //处理中
//        flowinfo.setOpertype("3");
//        List<Flowinfo> list1=dangerContentService.getInfoDetailJg(flowinfo);
//        if(list1!=null&&list1.size()>0){
//            model.addAttribute("clz",dangerContentService.getInfoDetailJg(flowinfo).get(0));
//        }
//        //已处理
//        flowinfo.setOpertype("4");
//        model.addAttribute("ycl",dangerContentService.getInfoDetailOne(flowinfo));
//        //反馈
//        flowinfo.setOpertype("6");
//        model.addAttribute("fk",dangerContentService.getInfoDetailOneList(flowinfo));
//        //确认退回
//        flowinfo.setOpertype("8");
//        model.addAttribute("qrth",dangerContentService.getInfoDetailOneList(flowinfo));
//        //已退回
//        flowinfo.setOpertype("9");
//        model.addAttribute("th",dangerContentService.getInfoDetailOne(flowinfo));
        String type = request.getParameter("type");
        if ("2".equals(type)) {
            return "danger/info_detail_2";
        }
        if ("3".equals(type)) {
            return "danger/info_detail_3";
        }
        return "danger/info_detail";
    }

    @RequestMapping("info/changerole")
    public String changerole(Model model, Query query, CollecterInfo collecterInfo, HttpServletRequest request) {
        int mark = 0;
        if ("".equals(collecterInfo.getJhzt()) || null == collecterInfo.getJhzt()) {
            collecterInfo.setJhzt(null);
        }
        if ("".equals(collecterInfo.getFjid()) || null == collecterInfo.getFjid()) {
            collecterInfo.setFjid(getMemberSession().getFjid());
            // collecterInfo=getMemberSession();
            mark = 1;
            if (getMemberSession().getRoletype().equals("1")) {
                collecterInfo.setPcsid(getMemberSession().getPcsid());
                collecterInfo.setSqid("");
            } else if (getMemberSession().getRoletype().equals("2")) {
                collecterInfo.setPcsid(getMemberSession().getPcsid());
                collecterInfo.setSqid(getMemberSession().getSqid());
            } else {
                collecterInfo.setPcsid("");
                collecterInfo.setSqid("");
            }

        }
        query.setData(collecterInfo);
        model.addAttribute("query", query);
        model.addAttribute("pager", collecterInfoService.getList(query));
        if ("".equals(collecterInfo.getFjid()) || null == collecterInfo.getFjid()) {
            model.addAttribute("dicone", collecterInfoService.getdict(collecterInfo));
        } else {
            CollecterInfo one = new CollecterInfo();
            one.setFjid(collecterInfo.getFjid());
            if ("".equals(getMemberSession().getFjid()) || null == getMemberSession().getFjid()) {
                CollecterInfo collecterInfo1 = new CollecterInfo();
                collecterInfo1.setFjid("");
                model.addAttribute("dicone", collecterInfoService.getdict(collecterInfo1));
            } else {
                model.addAttribute("dicone", collecterInfoService.getonedict(one));
            }
            if (getMemberSession().getRoletype().equals("1") || getMemberSession().getRoletype().equals("2")) {
                CollecterInfo collecterInfo1 = new CollecterInfo();
                collecterInfo1.setFjid(getMemberSession().getPcsid());
                model.addAttribute("dictwo", collecterInfoService.getonedict(collecterInfo1));
            } else {
                model.addAttribute("dictwo", collecterInfoService.getdict(one));
            }
            if (getMemberSession().getRoletype().equals("1")) {
                collecterInfo.setPcsid(getMemberSession().getPcsid());
                if (!"".equals(collecterInfo.getPcsid()) && null != collecterInfo.getPcsid()) {
                    one.setPcsid(collecterInfo.getPcsid());
                    model.addAttribute("dicthree", collecterInfoService.getdict(collecterInfo));
                }
            } else if (getMemberSession().getRoletype().equals("2")) {
                CollecterInfo collecterInfo1 = new CollecterInfo();
                collecterInfo1.setFjid(getMemberSession().getSqid());
                model.addAttribute("dicthree", collecterInfoService.getonedict(collecterInfo1));
            } else {
                if (!"".equals(collecterInfo.getPcsid()) && null != collecterInfo.getPcsid()) {
                    one.setPcsid(collecterInfo.getPcsid());
                    model.addAttribute("dicthree", collecterInfoService.getdict(collecterInfo));
                }
            }

        }

        return "danger/info_role";
    }

    @RequestMapping("info/fkrole")
    public String fkrole(Model model, Query query, CollecterInfo collecterInfo, HttpServletRequest request) {
        int mark = 0;
        if ("".equals(collecterInfo.getJhzt()) || null == collecterInfo.getJhzt()) {
            collecterInfo.setJhzt(null);
        }
        if ("".equals(collecterInfo.getFjid()) || null == collecterInfo.getFjid()) {
            collecterInfo.setFjid(getMemberSession().getFjid());
            // collecterInfo=getMemberSession();
            mark = 1;
            if (getMemberSession().getRoletype().equals("1")) {
                collecterInfo.setPcsid(getMemberSession().getPcsid());
                collecterInfo.setSqid("");
            } else if (getMemberSession().getRoletype().equals("2")) {
                collecterInfo.setPcsid(getMemberSession().getPcsid());
                collecterInfo.setSqid(getMemberSession().getSqid());
            } else {
                collecterInfo.setPcsid("");
                collecterInfo.setSqid("");
            }

        }
        query.setData(collecterInfo);
        model.addAttribute("query", query);
        model.addAttribute("pager", collecterInfoService.getList2(query));
        if ("".equals(collecterInfo.getFjid()) || null == collecterInfo.getFjid()) {
            model.addAttribute("dicone", collecterInfoService.getdict(collecterInfo));
        } else {
            CollecterInfo one = new CollecterInfo();
            one.setFjid(collecterInfo.getFjid());
            if ("".equals(getMemberSession().getFjid()) || null == getMemberSession().getFjid()) {
                CollecterInfo collecterInfo1 = new CollecterInfo();
                collecterInfo1.setFjid("");
                model.addAttribute("dicone", collecterInfoService.getdict(collecterInfo1));
            } else {
                model.addAttribute("dicone", collecterInfoService.getonedict(one));
            }
            if (getMemberSession().getRoletype().equals("1") || getMemberSession().getRoletype().equals("2")) {
                CollecterInfo collecterInfo1 = new CollecterInfo();
                collecterInfo1.setFjid(getMemberSession().getPcsid());
                model.addAttribute("dictwo", collecterInfoService.getonedict(collecterInfo1));
            } else {
                model.addAttribute("dictwo", collecterInfoService.getdict(one));
            }
            if (getMemberSession().getRoletype().equals("1")) {
                collecterInfo.setPcsid(getMemberSession().getPcsid());
                if (!"".equals(collecterInfo.getPcsid()) && null != collecterInfo.getPcsid()) {
                    one.setPcsid(collecterInfo.getPcsid());
                    model.addAttribute("dicthree", collecterInfoService.getdict(collecterInfo));
                }
            } else if (getMemberSession().getRoletype().equals("2")) {
                CollecterInfo collecterInfo1 = new CollecterInfo();
                collecterInfo1.setFjid(getMemberSession().getSqid());
                model.addAttribute("dicthree", collecterInfoService.getonedict(collecterInfo1));
            } else {
                if (!"".equals(collecterInfo.getPcsid()) && null != collecterInfo.getPcsid()) {
                    one.setPcsid(collecterInfo.getPcsid());
                    model.addAttribute("dicthree", collecterInfoService.getdict(collecterInfo));
                }
            }

        }

        return "danger/info_role2";
    }

    @ResponseBody
    @RequestMapping(value = "jl")
    public JSONArray jl(CollecterInfo collecterInfo, HttpServletRequest request) {
        List<CollecterInfo> list = collecterInfoService.getjl(collecterInfo);
        JSONArray arr = new JSONArray();
        JSONArray array2 = new JSONArray();
        array2.add("");
        array2.add("请选择");
        arr.add(JSONObject.parse(array2.toJSONString()));
        for (CollecterInfo l : list) {
            JSONArray array = new JSONArray();
            array.add(l.getId());
            array.add(l.getName());
            arr.add(JSONObject.parse(array.toJSONString()));

        }
        System.out.println("===========================" + arr.toJSONString());
        return arr;
    }

    @ResponseBody
    @RequestMapping(value = "childtype")
    public JSONArray childtype(DangerContent dc, HttpServletRequest request) {
        dc.setType(request.getParameter("id"));
        List<DangerContent> list = collecterInfoService.getChildtype(dc);
        JSONArray arr = new JSONArray();
        JSONArray array2 = new JSONArray();
        array2.add("");
        array2.add("请选择");
        arr.add(JSONObject.parse(array2.toJSONString()));
        for (DangerContent l : list) {
            JSONArray array = new JSONArray();
            array.add(l.getChildtype());
            array.add(l.getName());
            arr.add(JSONObject.parse(array.toJSONString()));

        }
        return arr;
    }

    @ResponseBody
    @RequestMapping("update")
    public Result update(CollecterInfo collecterInfo) {
        collecterInfo.setRole(collecterInfo.getRole() + ",1");
        collecterInfo.setRole(collecterInfo.getRole().replaceAll(",,", ","));
        if (collecterInfo.getPcsid().equals(collecterInfo.getSqid())) {
            collecterInfo.setRoletype("1");
        } else {
            collecterInfo.setRoletype("2");
        }
        if (!"".equals(collecterInfo.getPassword()) && null != collecterInfo.getPassword()) {

        } else {
            collecterInfo.setPassword(MD5Util.getMD5String("123455"));
        }
        return collecterInfoService.updateRole(collecterInfo);
    }

    @ResponseBody
    @RequestMapping("update2")
    public Result update2(CollecterInfo collecterInfo) {
        collecterInfo.setRole(collecterInfo.getRole() + ",2");
        collecterInfo.setRole(collecterInfo.getRole().replaceAll(",,", ","));
        if (collecterInfo.getPcsid().equals(collecterInfo.getSqid())) {
            collecterInfo.setRoletype("1");
        } else {
            collecterInfo.setRoletype("2");
        }
        if (!"".equals(collecterInfo.getPassword()) && null != collecterInfo.getPassword()) {

        } else {
            collecterInfo.setPassword(MD5Util.getMD5String("123455"));
        }
        return collecterInfoService.updateRole(collecterInfo);
    }

    @ResponseBody
    @RequestMapping("qxupdate")
    public Result qxupdate(CollecterInfo collecterInfo) {
        String id = "";
        String[] arr = collecterInfo.getRole().split(",");
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].equals("1") || "".equals(arr[i]) || null == arr[i]) {

            } else {
                id += arr[i] + ",";
            }
        }
        collecterInfo.setRole(id);
        return collecterInfoService.updateRole(collecterInfo);
    }

    @ResponseBody
    @RequestMapping("qxupdate2")
    public Result qxupdate2(CollecterInfo collecterInfo) {
        String id = "";
        String[] arr = collecterInfo.getRole().split(",");
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].equals("2") || "".equals(arr[i]) || null == arr[i]) {

            } else {
                id += arr[i] + ",";
            }
        }
        collecterInfo.setRole(id);
        return collecterInfoService.updateRole(collecterInfo);
    }

    @RequestMapping("info/tj/{deep}")
    public String tj(@PathVariable("deep") int deep, Model model, HttpServletRequest request, Query query) {
        //根据层级和id来确定数据
        String id = request.getParameter("id");
        String yhlb = request.getParameter("yhlb");
        CollecterInfo cInfo = (CollecterInfo) request.getSession().getAttribute("aqyhuser");
        if (deep == 1) {
            if ("0".equals(cInfo.getRoletype())) {
                if (cInfo.getFjid() == null || ("".equals(cInfo.getFjid()))) {
                    deep = 1;
                } else {
                    deep = 2;
                    id = cInfo.getFjid();
                }
            }
            if ("1".equals(cInfo.getRoletype())) {
                deep = 3;
                id = cInfo.getPcsid();
            }
            if ("2".equals(cInfo.getRoletype())) {
                deep = 4;
                id = cInfo.getSqid();
            }
        }
        model.addAttribute("cInfo", cInfo);
        CollecterInfo collecterInfo = new CollecterInfo();
        collecterInfo.setId(id);
        collecterInfo.setYhlb(yhlb);
        query.setData(collecterInfo);
        model.addAttribute("timeChoose", query);
        List<Qytj> list = new ArrayList<Qytj>();
        list = collecterInfoService.qhtj(deep, query);
        Qytj total = new Qytj();
        total.setName("合计");
        total.setId("-1");
        for (int i = 0; i < list.size(); i++) {
            total.setSbs(total.getSbs() + list.get(i).getSbs());
            total.setWsh(total.getWsh() + list.get(i).getWsh());
            total.setThsbss(total.getThsbss() + list.get(i).getThsbss());
            total.setThscf(total.getThscf() + list.get(i).getThscf());
            total.setYsh(total.getYsh() + list.get(i).getYsh());
            total.setLzs(total.getLzs() + list.get(i).getLzs());
            total.setZjzg(total.getZjzg() + list.get(i).getZjzg());
            total.setCfzg(total.getCfzg() + list.get(i).getCfzg());
            total.setJdqrs(total.getJdqrs() + list.get(i).getJdqrs());
            total.setQqrs(total.getQqrs() + list.get(i).getQqrs());
            total.setWfk(total.getWfk() + list.get(i).getWfk());
        }
        if (total.getYsh() != 0) {
            double f = new BigDecimal((float) total.getQqrs() * 100 / total.getYsh()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            total.setZgl(String.format("%.2f", f));
        } else {
            total.setZgl("0");
        }
        list.add(total);
        model.addAttribute("list", list);
        if (deep == 1) {
            return "danger/fj_list";
        } else if (deep == 2) {
            return "danger/pcs_list";
        } else {
            return "danger/sq_list";
        }
    }


    @RequestMapping("info/typetj/{deep}")
    public String typetj(@PathVariable("deep") int deep, Model model, HttpServletRequest request, Query query) {
        //根据层级和id来确定数据
        String id = request.getParameter("id");
        CollecterInfo cInfo = (CollecterInfo) request.getSession().getAttribute("aqyhuser");
        if (deep == 1) {
            if ("0".equals(cInfo.getRoletype())) {
                if (cInfo.getFjid() == null || ("".equals(cInfo.getFjid()))) {
                    deep = 1;
                } else {
                    deep = 2;
                    id = cInfo.getFjid();
                }
            }
            if ("1".equals(cInfo.getRoletype())) {
                deep = 3;
                id = cInfo.getPcsid();
            }
            if ("2".equals(cInfo.getRoletype())) {
                deep = 4;
                id = cInfo.getSqid();
            }
        }
        model.addAttribute("cInfo", cInfo);
        query.setData(id);
        model.addAttribute("timeChoose", query);
        List<TypeTj> list = new ArrayList<TypeTj>();
        list = collecterInfoService.typetj(deep, query);
        TypeTj total = new TypeTj();
        total.setName("合计");
        total.setId("-1");
        for (int i = 0; i < list.size(); i++) {
            total.setCount1(total.getCount1() + list.get(i).getCount1());
            total.setCount2(total.getCount2() + list.get(i).getCount2());
            total.setCount3(total.getCount3() + list.get(i).getCount3());
            total.setCount4(total.getCount4() + list.get(i).getCount4());
            total.setCount5(total.getCount5() + list.get(i).getCount5());
            total.setCount6(total.getCount6() + list.get(i).getCount6());
            total.setCount7(total.getCount7() + list.get(i).getCount7());
            total.setCount8(total.getCount8() + list.get(i).getCount8());
            total.setCount9(total.getCount9() + list.get(i).getCount9());
            total.setCount10(total.getCount10() + list.get(i).getCount10());
            total.setCount11(total.getCount11() + list.get(i).getCount11());
            total.setCount12(total.getCount12() + list.get(i).getCount12());
            total.setCount13(total.getCount13() + list.get(i).getCount13());
            total.setCount14(total.getCount14() + list.get(i).getCount14());
            total.setCount15(total.getCount15() + list.get(i).getCount15());
            total.setCount16(total.getCount16() + list.get(i).getCount16());
            total.setCount17(total.getCount17() + list.get(i).getCount17());
            total.setCount18(total.getCount18() + list.get(i).getCount18());
            total.setCount19(total.getCount19() + list.get(i).getCount19());
            total.setCount20(total.getCount20() + list.get(i).getCount20());
            total.setCount21(total.getCount21() + list.get(i).getCount21());
            total.setShycount(total.getShycount() + list.get(i).getShycount());
            total.setCzfcount(total.getCzfcount() + list.get(i).getCzfcount());
            total.setDdccount(total.getDdccount() + list.get(i).getDdccount());
            total.setTotalcount(total.getTotalcount() + list.get(i).getTotalcount());
        }
        list.add(total);
        model.addAttribute("list", list);
        if (deep == 1) {
            return "danger/typetj/fj_list";
        } else if (deep == 2) {
            return "danger/typetj/pcs_list";
        } else {
            return "danger/typetj/sq_list";
        }
    }


    @RequestMapping("info/typetj/detail/{deep}")
    public String detail(@PathVariable("deep") int deep, Model model, HttpServletRequest request, Query query) {
        //根据层级和地区和类别来确定数据
        String fjid = request.getParameter("fjid");//区
        String pcsid = request.getParameter("pcsid");//街道
        String sqid = request.getParameter("sqid");//社区
        //排除合计
        fjid = Objects.equals(fjid, "-1") ? null : fjid;
        pcsid = Objects.equals(pcsid, "-1") ? null : pcsid;
        sqid = Objects.equals(sqid, "-1") ? null : sqid;
        String childType = request.getParameter("childType");//子类型
        String type = request.getParameter("type");//类型
        CollecterInfo cInfo = new CollecterInfo();
        cInfo.setFjid(fjid);
        cInfo.setPcsid(pcsid);
        cInfo.setSqid(sqid);


        cInfo.setChildtype(childType);
        cInfo.setType(type);
        model.addAttribute("cInfo", cInfo);
        query.setData(cInfo);
        model.addAttribute("query", query);
        model.addAttribute("type", type);
        model.addAttribute("childType", childType);
        model.addAttribute("timeChoose", query);
        model.addAttribute("pager", dangerContentService.getTypeDetailList(query));
        if (deep == 1) {
            return "danger/typetj/detail_fj_list";
        } else if (deep == 2) {
            return "danger/typetj/detail_pcs_list";
        } else {
            return "danger/typetj/detail_sq_list";
        }
    }


    @RequestMapping("info/xxtj/{deep}")
    public String xxtj(@PathVariable("deep") int deep, Model model, HttpServletRequest request, Query query) {
        //根据层级和id来确定数据
        String id = request.getParameter("id");
        CollecterInfo cInfo = (CollecterInfo) request.getSession().getAttribute("aqyhuser");
        if (deep == 1) {
            if ("0".equals(cInfo.getRoletype())) {
                if (cInfo.getFjid() == null || ("".equals(cInfo.getFjid()))) {
                    deep = 1;
                } else {
                    deep = 2;
                    id = cInfo.getFjid();
                }
            }
            if ("1".equals(cInfo.getRoletype())) {
                deep = 3;
                id = cInfo.getPcsid();
            }
            if ("2".equals(cInfo.getRoletype())) {
                deep = 4;
                id = cInfo.getSqid();
            }
        }
        model.addAttribute("cInfo", cInfo);
        query.setData(id);
        model.addAttribute("timeChoose", query);
        List<XxTj> list = new ArrayList<XxTj>();
        list = collecterInfoService.xxtj(deep, query);
        XxTj total = new XxTj();
        total.setName("合计");
        total.setId("-1");
        for (int i = 0; i < list.size(); i++) {
            total.setGlmj(total.getGlmj() + list.get(i).getGlmj());
            total.setZlmj(total.getZlmj() + list.get(i).getZlmj());
            total.setWjmj(total.getWjmj() + list.get(i).getWjmj());
            total.setLhzf(total.getLhzf() + list.get(i).getLhzf());
            total.setTytc(total.getTytc() + list.get(i).getTytc());
            total.setTz(total.getTz() + list.get(i).getTz());
            total.setTstd(total.getTstd() + list.get(i).getTstd());
            total.setZltzsy(total.getZltzsy() + list.get(i).getZltzsy());
            total.setCf(total.getCf() + list.get(i).getCf());
            total.setBlwgjz(total.getBlwgjz() + list.get(i).getBlwgjz());
            total.setYtdsr(total.getYtdsr() + list.get(i).getYtdsr());
            total.setJgrs(total.getJgrs() + list.get(i).getJgrs());
            total.setFkje(total.getFkje() + list.get(i).getFkje());
            total.setXzjlrs(total.getXzjlrs() + list.get(i).getXzjlrs());
            total.setXsjlrs(total.getXsjlrs() + list.get(i).getXsjlrs());
            total.setQbhsrs(total.getQbhsrs() + list.get(i).getQbhsrs());
            total.setYtssfzr(total.getYtssfzr() + list.get(i).getYtssfzr());
            total.setZrzj(total.getZrzj() + list.get(i).getZrzj());
        }
        list.add(total);
        model.addAttribute("list", list);
        if (deep == 1) {
            return "danger/xxtj/fj_list";
        } else if (deep == 2) {
            return "danger/xxtj/pcs_list";
        } else {
            return "danger/xxtj/sq_list";
        }
    }

    @RequestMapping("info/xxtj/detail/{deep}")
    public String xxtjDetail(@PathVariable("deep") int deep, Model model, HttpServletRequest request, CollecterInfo cInfo, Query query) {
        //根据层级和地区和类别来确定数据
        String fjid = request.getParameter("fjid");//区
        String pcsid = request.getParameter("pcsid");//街道
        String sqid = request.getParameter("sqid");//社区
        //排除合计
        fjid = Objects.equals(fjid, "-1") ? null : fjid;
        pcsid = Objects.equals(pcsid, "-1") ? null : pcsid;
        sqid = Objects.equals(sqid, "-1") ? null : sqid;
        cInfo.setFjid(fjid);
        cInfo.setPcsid(pcsid);
        cInfo.setSqid(sqid);
        String column = request.getParameter("column");
        String table = "";
        String table_V_AQYH_FLOW_CFCS = "V_AQYH_FLOW_CFCS";
        String[] column_V_AQYH_FLOW_CFCS = new String[]{"jgrs", "fkje", "xzjlrs", "xsjlrs", "qbhsrs"};
        String table_V_AQYH_FLOW_ZGCS = "V_AQYH_FLOW_ZGCS";
        String[] column_V_AQYH_FLOW_ZGCS = new String[]{"glmj", "zlmj", "wjmj"
                , "lhzf", "tytc", "tz", "tstd", "zltzsy", "cf", "blwgjz", "ytdsr"};
        if (Arrays.asList(column_V_AQYH_FLOW_CFCS).contains(column)) {
            table = "V_AQYH_FLOW_CFCS";
        } else if (Arrays.asList(column_V_AQYH_FLOW_ZGCS).contains(column)) {
            table = "V_AQYH_FLOW_ZGCS";
        }
        Map<String, String> map = new HashMap<>();
        map.put("column", column);
        map.put("table", table);
        query.setMap(map);
        query.setData(cInfo);
        model.addAttribute("cInfo", cInfo);
        model.addAttribute("timeChoose", query);
        model.addAttribute("query", query);
        model.addAttribute("column", column);
        Pager<DangerContent> list = dangerContentService.xxtjDetailList(query);
        model.addAttribute("pager", list);
        if (deep == 1) {
            return "danger/xxtj/detail_fj_list";
        } else if (deep == 2) {
            return "danger/xxtj/detail_pcs_list";
        } else {
            return "danger/xxtj/detail_sq_list";
        }
    }

    /**
     * 从整改措施点击进去约谈和责任人列表
     *
     * @param deep
     * @param model
     * @param request
     * @param cInfo
     * @param query
     * @return
     */
    @RequestMapping("info/xxtj/wzzjdetail/{deep}")
    public String wzzjdetail(@PathVariable("deep") int deep, Model model, HttpServletRequest request, CollecterInfo cInfo, Query query) {
        //根据层级和地区和类别来确定数据
        String fjid = request.getParameter("fjid");//区
        String pcsid = request.getParameter("pcsid");//街道
        String sqid = request.getParameter("sqid");//社区
        String wzzjlb = request.getParameter("wzzjlb");
        //排除合计
        fjid = Objects.equals(fjid, "-1") ? null : fjid;
        pcsid = Objects.equals(pcsid, "-1") ? null : pcsid;
        sqid = Objects.equals(sqid, "-1") ? null : sqid;
        cInfo.setFjid(fjid);
        cInfo.setPcsid(pcsid);
        cInfo.setSqid(sqid);

        query.setData(cInfo);
        model.addAttribute("cInfo", cInfo);

        model.addAttribute("timeChoose", query);
        model.addAttribute("query", query);
        model.addAttribute("deep", deep);
        model.addAttribute("wzzjlb", wzzjlb);
        model.addAttribute("pager", wzzjService.getWzzjList(query));
        if (Objects.equals(wzzjlb, "1")) {
            return "danger/xxtj/detail_info_ytlist";
        } else if (Objects.equals(wzzjlb, "2")) {
            return "danger/xxtj/detail_info_zzlist";
        }
        return null;
    }


    @RequestMapping("info/xxtjExport/{deep}")
    public void xxtjExport(@PathVariable("deep") int deep, Model model, HttpServletRequest request, Query query, HttpServletResponse response) {
        //根据层级和id来确定数据
        String id = "";
        CollecterInfo cInfo = (CollecterInfo) request.getSession().getAttribute("aqyhuser");
        if (deep == 1) {
            if ("0".equals(cInfo.getRoletype())) {
                if (cInfo.getFjid() == null || ("".equals(cInfo.getFjid()))) {
                    deep = 1;
                } else {
                    deep = 2;
                    id = cInfo.getFjid();
                }
            }
            if ("1".equals(cInfo.getRoletype())) {
                deep = 3;
                id = cInfo.getPcsid();
            }
            if ("2".equals(cInfo.getRoletype())) {
                deep = 4;
                id = cInfo.getSqid();
            }
        }
        query.setData(id);
        List<XxTj> list = new ArrayList<XxTj>();
        list = collecterInfoService.xxtj(deep, query);
        XxTj total = new XxTj();
        total.setName("合计");
        total.setId("-1");
        for (int i = 0; i < list.size(); i++) {
            total.setGlmj(total.getGlmj() + list.get(i).getGlmj());
            total.setZlmj(total.getZlmj() + list.get(i).getZlmj());
            total.setWjmj(total.getWjmj() + list.get(i).getWjmj());
            total.setLhzf(total.getLhzf() + list.get(i).getLhzf());
            total.setTytc(total.getTytc() + list.get(i).getTytc());
            total.setTz(total.getTz() + list.get(i).getTz());
            total.setTstd(total.getTstd() + list.get(i).getTstd());
            total.setZltzsy(total.getZltzsy() + list.get(i).getZltzsy());
            total.setCf(total.getCf() + list.get(i).getCf());
            total.setBlwgjz(total.getBlwgjz() + list.get(i).getBlwgjz());
            total.setYtdsr(total.getYtdsr() + list.get(i).getYtdsr());
            total.setJgrs(total.getJgrs() + list.get(i).getJgrs());
            total.setFkje(total.getFkje() + list.get(i).getFkje());
            total.setXzjlrs(total.getXzjlrs() + list.get(i).getXzjlrs());
            total.setXsjlrs(total.getXsjlrs() + list.get(i).getXsjlrs());
            total.setQbhsrs(total.getQbhsrs() + list.get(i).getQbhsrs());
            total.setYtssfzr(total.getYtssfzr() + list.get(i).getYtssfzr());
            total.setZrzj(total.getZrzj() + list.get(i).getZrzj());
        }
        list.add(total);
        collecterInfoService.exportXxtj(response, list, deep);
    }

    @RequestMapping("info/qytjExport/{deep}")
    public void qytjExport(@PathVariable("deep") int deep, Model model, HttpServletRequest request, Query query, HttpServletResponse response) {
        //根据层级和id来确定数据
        String id = "";
        CollecterInfo cInfo = (CollecterInfo) request.getSession().getAttribute("aqyhuser");
        if (deep == 1) {
            if ("0".equals(cInfo.getRoletype())) {
                if (cInfo.getFjid() == null || ("".equals(cInfo.getFjid()))) {
                    deep = 1;
                } else {
                    deep = 2;
                    id = cInfo.getFjid();
                }
            }
            if ("1".equals(cInfo.getRoletype())) {
                deep = 3;
                id = cInfo.getPcsid();
            }
            if ("2".equals(cInfo.getRoletype())) {
                deep = 4;
                id = cInfo.getSqid();
            }
        }
        CollecterInfo collecterInfo = new CollecterInfo();
        String yhlb = request.getParameter("yhlb");
        collecterInfo.setId(id);
        collecterInfo.setYhlb(yhlb);
        query.setData(collecterInfo);
        List<Qytj> list = new ArrayList<Qytj>();
        list = collecterInfoService.qhtj(deep, query);
        Qytj total = new Qytj();
        total.setName("合计");
        total.setId("-1");
        for (int i = 0; i < list.size(); i++) {
            total.setSbs(total.getSbs() + list.get(i).getSbs());
            total.setWsh(total.getWsh() + list.get(i).getWsh());
            total.setThsbss(total.getThsbss() + list.get(i).getThsbss());
            total.setThscf(total.getThscf() + list.get(i).getThscf());
            total.setYsh(total.getYsh() + list.get(i).getYsh());
            total.setLzs(total.getLzs() + list.get(i).getLzs());
            total.setZjzg(total.getZjzg() + list.get(i).getZjzg());
            total.setCfzg(total.getCfzg() + list.get(i).getCfzg());
            total.setJdqrs(total.getJdqrs() + list.get(i).getJdqrs());
            total.setQqrs(total.getQqrs() + list.get(i).getQqrs());
            total.setWfk(total.getWfk() + list.get(i).getWfk());
        }
        if (total.getYsh() != 0) {
            double f = new BigDecimal((float) total.getQqrs() * 100 / total.getYsh()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            total.setZgl(String.format("%.2f", f));
        } else {
            total.setZgl("0");
        }
        list.add(total);
        collecterInfoService.exportQytj(response, list, deep);
    }

    @RequestMapping("info/typetjExport/{deep}")
    public void typetjExport(@PathVariable("deep") int deep, Model model, HttpServletRequest request, Query query, HttpServletResponse response) {
        //根据层级和id来确定数据
        String id = "";
        CollecterInfo cInfo = (CollecterInfo) request.getSession().getAttribute("aqyhuser");
        if (deep == 1) {
            if ("0".equals(cInfo.getRoletype())) {
                if (cInfo.getFjid() == null || ("".equals(cInfo.getFjid()))) {
                    deep = 1;
                } else {
                    deep = 2;
                    id = cInfo.getFjid();
                }
            }
            if ("1".equals(cInfo.getRoletype())) {
                deep = 3;
                id = cInfo.getPcsid();
            }
            if ("2".equals(cInfo.getRoletype())) {
                deep = 4;
                id = cInfo.getSqid();
            }
        }
        query.setData(id);
        List<TypeTj> list = new ArrayList<TypeTj>();
        list = collecterInfoService.typetj(deep, query);
        TypeTj total = new TypeTj();
        total.setName("合计");
        total.setId("-1");
        for (int i = 0; i < list.size(); i++) {
            total.setCount1(total.getCount1() + list.get(i).getCount1());
            total.setCount2(total.getCount2() + list.get(i).getCount2());
            total.setCount3(total.getCount3() + list.get(i).getCount3());
            total.setCount4(total.getCount4() + list.get(i).getCount4());
            total.setCount5(total.getCount5() + list.get(i).getCount5());
            total.setCount6(total.getCount6() + list.get(i).getCount6());
            total.setCount7(total.getCount7() + list.get(i).getCount7());
            total.setCount8(total.getCount8() + list.get(i).getCount8());
            total.setCount9(total.getCount9() + list.get(i).getCount9());
            total.setCount10(total.getCount10() + list.get(i).getCount10());
            total.setCount11(total.getCount11() + list.get(i).getCount11());
            total.setCount12(total.getCount12() + list.get(i).getCount12());
            total.setCount13(total.getCount13() + list.get(i).getCount13());
            total.setCount14(total.getCount14() + list.get(i).getCount14());
            total.setCount15(total.getCount15() + list.get(i).getCount15());
            total.setCount16(total.getCount16() + list.get(i).getCount16());
            total.setCount17(total.getCount17() + list.get(i).getCount17());
            total.setCount18(total.getCount18() + list.get(i).getCount18());
            total.setCount19(total.getCount19() + list.get(i).getCount19());
            total.setCount20(total.getCount20() + list.get(i).getCount20());
            total.setCount21(total.getCount21() + list.get(i).getCount21());
            total.setShycount(total.getShycount() + list.get(i).getShycount());
            total.setCzfcount(total.getCzfcount() + list.get(i).getCzfcount());
            total.setDdccount(total.getDdccount() + list.get(i).getDdccount());
            total.setTotalcount(total.getTotalcount() + list.get(i).getTotalcount());
        }
        list.add(total);
        collecterInfoService.exportTypetj(response, list, deep);
    }


    @RequestMapping("info/tj/qytjDetail")
    public String qytjDetail(Model model, HttpServletRequest request, Query query, Qytj qytj) {
        query.setData(qytj);
        model.addAttribute("pager", dangerContentService.getQytjDetail(query));
        model.addAttribute("query", query);
        return "danger/qytjDetail";
    }
}
